package map.abstractor.main;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import javax.xml.parsers.ParserConfigurationException;

import map.abstractor.xaml2uimodel.Xaml2XMLModelVisitor;
import map.abstractor.xaml2uimodel.base.XamlDocument;
import map.abstractor.xmlmodel.XMLObject;
import map.tools.plateform.MappingTableSerializer;

import org.xml.sax.SAXException;

import uimigration.mappingmodel.MappingActionEvent;
import uimigration.mappingmodel.MappingTable;



public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws SAXException 
	 * @throws ParserConfigurationException 
	 */
	public static final String XMLFILESPATH=".//models//xml//"; 
	public static final String APIFILESPATH=".//models//api//";  //  @jve:decl-index=0:
	public static final String DEVICEFILESPATH=".//models//device//";  //  @jve:decl-index=0:
	public static final String TABLEFILESPATH="models//tables//";  //  @jve:decl-index=0:


	public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
		
	
		//System.out.println(Xaml2Model("C:\\Temp\\instances\\Window1.xaml"));
		
		//SurfaceWindow1.xaml
		
		MappingTable mapping= new MappingTableSerializer().load(( new File(TABLEFILESPATH+"MappingTable.xmi")));

		if(mapping!=null)
			for(MappingActionEvent beh:mapping.getActionsMapping())
			{
				System.out.println(beh.toString());
			}
	}
	public static String Xaml2Model(String fileName){
		try{
			XamlDocument fd = new XamlDocument(fileName);
			Xaml2XMLModelVisitor lv = new Xaml2XMLModelVisitor(null);
			XMLObject root = lv.visit(fd);
			
			return lv.Xmlheader+root.toString();

		}catch(Exception e){
			e.printStackTrace();
			return "Erreur";
		}
	}
	public static void saveFile(String name, String content) throws IOException{
		File file = new File(name);
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF8"));
		out.write(content);
		out.close();	
	}
	

	
}
